home *** CD-ROM | disk | FTP | other *** search
/ PC Format (South-Africa) 2001 June / PCFJune.iso / mweb / MWEB Utils / ws295sdk.exe / Ws2sdkzp.exe / SAMPLES / LAYERED / DOVERLAP.H < prev    next >
Encoding:
C/C++ Source or Header  |  1997-06-06  |  5.0 KB  |  169 lines

  1. /*++
  2.  
  3.  
  4.      Copyright c 1996 Intel Corporation
  5.      All Rights Reserved
  6.  
  7.      Permission is granted to use, copy and distribute this software and
  8.      its documentation for any purpose and without fee, provided, that
  9.      the above copyright notice and this statement appear in all copies.
  10.      Intel makes no representations about the suitability of this
  11.      software for any purpose.  This software is provided "AS IS."
  12.  
  13.      Intel specifically disclaims all warranties, express or implied,
  14.      and all liability, including consequential and other indirect
  15.      damages, for the use of this software, including liability for
  16.      infringement of any proprietary rights, and including the
  17.      warranties of merchantability and fitness for a particular purpose.
  18.      Intel does not assume any responsibility for any errors which may
  19.      appear in this software nor any responsibility to update it.
  20.  
  21.  
  22. Module Name:
  23.  
  24. doverlap.h
  25.  
  26. Abstract:
  27.  
  28.     This module defines the DOVERLAPPEDSTRUCTMGR class.  This class
  29.     maintains a pool of internal overlapped structures.  These structures
  30.     are used to store the information the layered service provider will
  31.     need to satisfy users overlapped I/O requests.
  32.  
  33. --*/
  34.  
  35. #ifndef _DOVERLAPPEDSTRUCTMGR_
  36. #define _DOVERLAPPEDSTRUCTMGR_
  37.  
  38.  
  39. #include <winsock2.h>
  40. #include "llist.h"
  41. #include "classfwd.h"
  42. #include "stddef.h"
  43.  
  44. #define  OUTSTANDINGOVERLAPPEDSTRUCTS 1000
  45. #define  STRUCTSIGNATURE 0xbeadface
  46. // Maximum number of buffers inside the structure (if we have to handle
  47. // more than that, we'll allocate from heap)
  48. #define  MAX_FAST_BUFS 8
  49.  
  50. // The internal overlapped struct
  51. typedef struct _INTERNALOVERLAPPEDSTRUCT
  52. {
  53.     DWORD                              iolSignature;
  54.     DWORD                              iolOperationType;
  55.     SOCKET                               iolSocket;
  56.     PDPROVIDER                         iolProvider;
  57.     union {
  58.         SOCKET                             iolProviderSocket;
  59.         SOCKET                               iolListenSocket;
  60.     };
  61.     WSATHREADID                        iolUserThreadId;
  62.     LPWSAOVERLAPPED                    iolUserOverlappedStruct;
  63.     LPWSAOVERLAPPED_COMPLETION_ROUTINE iolUserCompletionRoutine;
  64.     union {
  65.         TRANSMIT_FILE_BUFFERS               iolTransmitBuffers;
  66.         struct {
  67.             union {
  68.                 WSABUF                               UserBuffers[MAX_FAST_BUFS];
  69. #define iolUserBuffers iolRest.UserBuffers
  70.                 LPWSABUF                           pUserBuffers;
  71. #define iolpUserBuffers iolRest.pUserBuffers
  72.                 LPVOID                               InputBuffer;
  73. #define iolInputBuffer iolRest.InputBuffer
  74.             };
  75.             union {
  76.                 DWORD                              UserBufferCount;
  77. #define iolUserBufferCount iolRest.UserBufferCount
  78.                 DWORD                               InputBufferLength;
  79. #define iolInputBufferLength iolRest.InputBufferLength
  80.             };
  81.             union {
  82.                 WSABUF                             InternalBuffers[MAX_FAST_BUFS];
  83. #define iolInternalBuffers iolRest.InternalBuffers
  84.                 LPWSABUF                           pInternalBuffers;
  85. #define iolpInternalBuffers iolRest.pInternalBuffers
  86.                 LPVOID                               OutputBuffer;
  87. #define iolOutputBuffer iolRest.OutputBuffer
  88.             };
  89.             union {
  90.                 DWORD                              InternalBufferCount;
  91. #define iolInternalBufferCount iolRest.InternalBufferCount
  92.                 DWORD                               OutputBufferLength;
  93. #define iolOutputBufferLength iolRest.OutputBufferLength
  94.             };
  95.         }                                    iolRest;
  96.     };
  97.     union {
  98.         struct sockaddr FAR *              iolSockAddr;
  99.         DWORD                               iolLocalAddressLength;
  100.         DWORD                               iolBytesToWrite;
  101.     };
  102.     union {
  103.         LPINT                              iolSockAddrLenPtr;
  104.         INT                                iolSockAddrLen;
  105.         DWORD                               iolRemoteAddressLength;
  106.         DWORD                               iolBytesPerSend;
  107.     };
  108.     union {
  109.         DWORD                              iolFlags;
  110.         DWORD                               iolIoControlCode;
  111.         SOCKET                               iolAcceptSocket;
  112.         HANDLE                               iolFileHandle;
  113.     };
  114.     DWORD                               iolReserved;
  115.     LIST_ENTRY                         iolListLinkage;
  116.     WSAOVERLAPPED                      iolInternalOverlappedStruct;
  117. } INTERNALOVERLAPPEDSTRUCT, *PINTERNALOVERLAPPEDSTRUCT;
  118.  
  119. class DOVERLAPPEDSTRUCTMGR
  120. {
  121.   public:
  122.  
  123.     DOVERLAPPEDSTRUCTMGR();
  124.  
  125.     INT
  126.     Initialize(
  127.         );
  128.  
  129.     ~DOVERLAPPEDSTRUCTMGR();
  130.  
  131.     PINTERNALOVERLAPPEDSTRUCT
  132.     AllocateOverlappedStruct(
  133.         );
  134.  
  135.     VOID
  136.     FreeOverlappedStruct(
  137.         LPWSAOVERLAPPED   pOverlappedStruct
  138.         );
  139.  
  140.     PINTERNALOVERLAPPEDSTRUCT
  141.     GetInternalOverlappedStructure (
  142.         LPWSAOVERLAPPED      pOverlappedStruct
  143.         );
  144.  
  145.   private:
  146.  
  147.     PINTERNALOVERLAPPEDSTRUCT
  148.     PopOverlappedStruct();
  149.  
  150.     VOID
  151.     PushOverlappedStruct(
  152.         LPWSAOVERLAPPED OverlappedStruct
  153.         );
  154.  
  155.     SINGLE_LIST_ENTRY m_overlapped_free_list;
  156.     // A list of available internal overlapped structs.
  157.  
  158.     CRITICAL_SECTION  m_overlapped_free_list_lock;
  159.     // Syncronization object for updateing m_overlapped_free_list.
  160.  
  161.     PBYTE             m_overlapped_struct_block;
  162.     // Pointer to the memory block containing the internal overlapped
  163.     // structures.
  164.  
  165.  
  166. };   // class DOVERLAPPEDSTRUCTMGR
  167.  
  168. #endif // _DOVERLAPPEDSTRUCTMGR_
  169.